package com.zjj.mybatis.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.zjj.mybatis.bean.User;

@Mapper
public interface UserDao {
	
	/**
	 * @Results 标志结果集，以及与库表字段的映射关系（一般用于实体对象属性与数据库字段不一致时使用）
	 * @return
	 */
	@Select("select id, name, age from user")
	@Results({
        @Result(property = "id", column = "id"),
        @Result(property = "age", column = "age"),
        @Result(property = "name", column = "name"),
	})
	List<User> queryUserList();

	@Select("select id, name, age from user where id = #{id}")
	User queryUserById(@Param("id") int id);

	@Insert("insert into user(name, age) values(#{name}, #{age})")
	boolean addUser(@Param("name") String name, @Param("age") int age);
	
	@Insert("insert into user(name, age) values(#{name}, #{age})")
	boolean addUserEntity(User user);

	@Update("update user set name = #{name}, age = #{age} where id = #{id}")
	boolean updateUser(@Param("name") String name, @Param("age") int age, 
			@Param("id") int id);

	@Delete("delete from user where id = #{id}")
	boolean deleteUser(int id);
}
